package ro.hex.remocadm;

/**
 * Class representing a channel.<br/>
 * Used when reading the channels from configuration file and populating
 * the channelList variable in GUI.java.
 * 
 * @author Iulian Virtejanu
 */
public class DirectXChannel implements Channel {
    private int vlcChannel;
    private String name;

    public DirectXChannel(int vlcChannel, String name) {
        this.vlcChannel = vlcChannel;
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getVlcChannel() {
        return vlcChannel;
    }

    public void setVlcChannel(int vlcChannel) {
        this.vlcChannel = vlcChannel;
    }

    @Override
    public String toString() {
        return getName();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final DirectXChannel other = (DirectXChannel) obj;
        if (this.vlcChannel != other.vlcChannel) {
            return false;
        }
        if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 97 * hash + this.vlcChannel;
        hash = 97 * hash + (this.name != null ? this.name.hashCode() : 0);
        return hash;
    }

    public static DirectXChannel parseChannel(String line) {

        line = line.substring("dx.".length());

        int indexOfPoint = line.indexOf('.');
        int indexOfEquals = line.indexOf('=');

        int num = Integer.parseInt(line.substring(indexOfPoint + 1, indexOfEquals));
        String nam = line.substring(indexOfEquals + 1);

        return new DirectXChannel(num, nam);
    }

}
